package bg.cinema_system.beans;

import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import bg.cinema_system.pojo.Movie;
import bg.cinema_system.pojo.Projection;
import bg.cinema_system.service.UserServeice;

@ManagedBean
@SessionScoped
public class StaffBean {
	
	private String type;
	private boolean isMovie;
	private String warning;
	private String message;
	
	private Movie moviePojo;
	private Projection projection;
	
	public StaffBean(){
		type = "projection";
		moviePojo = new Movie();
		projection = new Projection();
	}
	
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public boolean isMovie() {
		return type.equals("movie") ?  true : false;
	}
	public void setMovie(boolean isMovie) {
		this.isMovie = isMovie;
	}
	public String getWarning() {
		return warning;
	}
	public void setWarning(String warning) {
		this.warning = warning;
	}
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	public Movie getMoviePojo() {
		return moviePojo;
	}
	public void setMoviePojo(Movie moviePojo) {
		this.moviePojo = moviePojo;
	}
	public Projection getProjection() {
		return projection;
	}
	public void setProjection(Projection projection) {
		this.projection = projection;
	}

	public String insertMovie(){
		boolean isMessgaDisplay = true;
		try {
			UserServeice.insertMovie(getMoviePojo());
		} catch (SQLException e) {
			isMessgaDisplay=false;
			setWarning("Movie does not inserted. Try again!");
			e.printStackTrace();
		}catch (ParseException e) {
			isMessgaDisplay = false;
			setWarning("Movie does not inserted. Try again!");
			e.printStackTrace();
		}
		if(isMessgaDisplay){
			setMessage("Successfully added movie.");
		}
		return "staff";
	}
	
	public String insertProjection(){
		boolean isMessgaDisplay = true;
		try {
			UserServeice.insertProjection(projection);
		} catch (SQLException e) {
			isMessgaDisplay=false;
			setWarning("Projection does not inserted. Try again!");
			e.printStackTrace();
		} catch (ParseException e) {
			isMessgaDisplay=false;
			setWarning("Projection does not inserted. Try again!");
			e.printStackTrace();
		}
		if(isMessgaDisplay){
			setMessage("Successfully added projection.");
		}
		return "staff";
	}
	
}
